<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .blue{
            background-color: lightskyblue;
        }
        .green{
            background-color: lightgreen;
        }
    </style>
    <script>
        function changeTrColor() {
           var arr=document.getElementsByTagName("tr")
             for (var i = 1;i<arr.length;i++){
                 if (i%2==0){
                     arr[i].className="blue";
                 }else {
                     arr[i].className="green";
                 }
             } 
        }
    </script>
</head>
<body onload="changeTrColor()">
        <table border="1" cellpadding="0" cellspacing="0" width="30%">
            <tr>
                <th>ID</th>
                <th>姓名</th>
                <th>专业</th>
            </tr>
            <tr>
                <td>20180201</td>
                <td>刘备</td>
                <td>全栈</td>
            </tr>
            <tr>
            <td>20180202</td>
            <td>曹操</td>
            <td>java</td>
            </tr>
            <tr>
            <td>20180203</td>
            <td>孙权</td>
            <td>Python</td>
            </tr>
            <tr>
            <td>20180204</td>
            <td>刘表</td>
            <td>大数据</td>
            </tr>
        </table>
</body>
</html>